package com.vdong.trade.trading.web.controller;

import com.vdong.trade.trading.common.contract.ApiContract;
import com.vdong.trade.trading.entity.dto.param.PaymentNotifyRequestDTO;
import com.vdong.trade.trading.facade.enums.PayChannelEnum;
import com.vdong.trade.trading.service.TransactionPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author <a href="mailto:clf@vdongzc.com">clf</a>
 * @Description: 处理支付回调
 * @Date Create on 2018-12-13 15:10:22
 * @since version1.0
 */
@RestController
public class PayController {

    @Autowired
    private TransactionPayService transactionPayService;

    /**
     * 微信支付异步回调
     *
     * @param resultXml
     * @return
     */
    @RequestMapping(value = ApiContract.I000000018)
    public String weChatPayNotify(@RequestBody String resultXml) {
        PaymentNotifyRequestDTO paymentNotifyRequest = new PaymentNotifyRequestDTO();
        paymentNotifyRequest.setPayChannel(PayChannelEnum.WECHAT_PAY.getCode());
        paymentNotifyRequest.setResultStr(resultXml);
        return transactionPayService.paymentResultNotify(paymentNotifyRequest);

        //告诉服务端消息处理的结果，避免不断的进行结果通知
        //response.setContentType("text/xml");
        //response.getWriter().print(notifyResponse.getResult());
    }

}
